
// http://benchmark.cocos2d-x.org/cocosvideo.mp4
const {ccclass, property} = cc._decorator;

@ccclass
export default class Main extends cc.Component {

    @property(cc.VideoPlayer) videoPlayer = null;
    @property(cc.Label) currentTime = null;

    onLoad() {

    }

    start() {
        
    }

    onVideoPlayerEvent (sender, event) {
        if (event === cc.VideoPlayer.EventType.CLICKED) {
            if (this.videoPlayer.isPlaying()) {
                this.videoPlayer.pause();
            } else {
                this.videoPlayer.play();
            }
        }
        else if (event === cc.VideoPlayer.EventType.READY_TO_PLAY || event === cc.VideoPlayer.EventType.META_LOADED) {
            
        }
        else if (event === cc.VideoPlayer.EventType.PLAYING) {
            
        }
    }

    keepRatioSwitch () {
        this.videoPlayer.keepAspectRatio = !this.videoPlayer.keepAspectRatio;
    }

    play () {
        this.videoPlayer.play();
    }

    pause () {
        this.videoPlayer.pause();
    }

    stop () {
        this.videoPlayer.stop();
    }

    update () {
        if (this.currentTime && this.videoPlayer.currentTime >= 0) {
            this.currentTime.string = this.videoPlayer.currentTime.toFixed(2) + ' / ' + this.videoPlayer.getDuration().toFixed(2);
        }
    }
}
